import * as Cesium from "cesium";
import { MapImageryProvider } from './coordTransform';

class ImageryProvider {
    constructor() {
        this.providerViewModels = [] //用来装各种影像服务
        this.imageryToProvide = []//影像服务

        // 未纠偏
        let gaode = new Cesium.UrlTemplateImageryProvider({
            url: "https://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
            subdomains: ["1", "2", "3", "4"],
            maximumLevel: 16,
            crs: "WGS84"
        })

        // 纠偏
        gaode = new MapImageryProvider({
            url: "https://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
            subdomains: ["1", "2", "3", "4"],
            maximumLevel: 16,
            crs: "WGS84"
        })

        const tenxun = new MapImageryProvider({
            url: "https://p2.map.gtimg.com/sateTiles/{z}/{sx}/{sy}/{x}_{reverseY}.jpg?version=229",
            customTags: {
                sx: function (imageryProvider, x, y, level) {
                    return x >> 4;
                },
                sy: function (imageryProvider, x, y, level) {
                    return ((1 << level) - y) >> 4
                }
            },
            crs: "WGS84"
            // 影像图
            // url: "https://p2.map.gtimg.com/sateTiles/{z}/{sx}/{sy}/{x}_{reverseY}.jpg?version=400",
            // 矢量图
            // url: "https://rt3.map.gtimg.com/tile?z={z}&x={x}&y={reverseY}&styleid=1&version=297",
            // 黑色风格
            // url: "https://rt3.map.gtimg.com/tile?z={z}&x={x}&y={reverseY}&styleid=4&scene=0",
            // 注记图1
            // url: "https://rt3.map.gtimg.com/tile?z={z}&x={x}&y={reverseY}&styleid=3&scene=0",
            // 注记图2
            // url: "https://rt3.map.gtimg.com/tile?z={z}&x={x}&y={reverseY}&styleid=2&version=297",
        })


        //天地图影像
        let key = 'b2e5435b11c60593c96eebf71fa5448d'
        const tiandi = new Cesium.WebMapTileServiceImageryProvider({
            url: "http://t{s}.tianditu.gov.cn/img_w/wmts?tk=4befa5ab78e9656c766335d1a007f570",
            layer: "img",
            style: "default",
            format: "tiles",
            tileMatrixSetID: "w",
            subdomains: ["0", "1", "2", "3", "4", "5", "6", "7"],
            maximumLevel: 18
        })

        const baidu = new MapImageryProvider({
            url: 'http://online2.map.bdimg.com/tile/?qt=tile&x={x}&y={y}&z={z}&udt=20190823',
            crs: "BD09" // 标识使用百度坐标系
        });



        //将自定义的影像追加到providerViewModels中
        const gdProviderModel = new Cesium.ProviderViewModel({
            name: "高德地图",
            iconUrl: "/images/satellite-v9.png", //自定义了一个天地图小图标
            tooltip: "高德地图",
            creationFunction: function () {
                return gaode; //对应之前定义的变量名
            }
        });

        const txProviderModel = new Cesium.ProviderViewModel({
            name: "腾讯地图",
            iconUrl: "/images/satellite-v9.png", //自定义了一个小图标
            tooltip: "腾讯地图",
            creationFunction: function () {
                return tenxun; //对应之前定义的变量名
            }
        });

        const tdProviderModel = new Cesium.ProviderViewModel({
            name: "天地图",
            iconUrl: "/images/tianditu.png",
            tooltip: "天地图",
            creationFunction: function () {
                return tiandi; //对应之前定义的变量名
            }
        });

        const bdProviderModel = new Cesium.ProviderViewModel({
            name: "百度地图",
            iconUrl: "/images/streets-v11.png",
            tooltip: "百度地图",
            creationFunction: function () {
                return baidu;
            }
        });

        

        const ywProviderModel = new Cesium.ProviderViewModel({
            name: "夜晚地球",
            iconUrl: "/images/dark-v10.png",
            tooltip: "夜晚地球",
            creationFunction: function () {
                return new Cesium.IonImageryProvider({ assetId: 3812 }); //对应之前定义的变量名
            }
        });

        this.providerViewModels.push(gdProviderModel, txProviderModel, tdProviderModel, bdProviderModel, ywProviderModel); //追加影像服务
        this.imageryToProvide.push(gaode, tenxun, tiandi, baidu, new Cesium.IonImageryProvider({ assetId: 3812 }))
    }
}

export default ImageryProvider;